<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>切换背景颜色</title>
    <style>
        .box{
            width: 100%;
            height: 100px;
            /* background-color: red; */
            /* transition: background-color 1s ease-in-out; */
        }
        .color{
            width: 600px;
            height: 100px;
            margin: 0 auto;

        }
        .color div{
            width: 80px;
            height: 40px;
            background-color: rgb(152, 243, 125);
            float: left;
            margin: 10px;
            padding-top: 10px;
            text-align: center;
            border: 2px red dashed;
        }
       
    </style>
</head>
<body>
    <div class="box" >
        <div class="color">
            <div style="color: red;">红色</div>
            <div style="color: yellow;">黄色</div>
            <div style="color: blue;">蓝色</div>
            <div>背景图片</div>
        </div>
        
    </div>
    <script>
        
        var red = document.querySelector('.color div:nth-child(1)');
       
        var yellow = document.querySelector('.color div:nth-child(2)');
        
        var blue = document.querySelector('.color div:nth-child(3)');
        
        var bg = document.querySelector('.color div:nth-child(4)');
       
       
        red.onclick = function(){
            document.body.style.backgroundColor = 'red';
            document.body.style.backgroundImage = '';
        }
        yellow.onclick = function(){            
            document.body.style.backgroundColor = 'yellow';
            document.body.style.backgroundImage = '';
        }
        blue.onclick = function(){
            document.body.style.backgroundColor = 'blue';
            document.body.style.backgroundImage = '';
        }
        bg.onclick = function(){
            document.body.style.backgroundImage = 'url(./logo.png)';
        }
    </script>
    
</body>
</html>